<template>
	<view class="">
		<cu-custom :isBack="true">
		</cu-custom>
		<view v-for="(item,index) in notices" :key="index" @tap="gotoInfo(item)">
			<view class="cu-card case margin-xs ">
				<view class="cu-item shadow">
					<view class="padding text-df" style="border-bottom:1px solid rgba(0, 0, 0, 0.1);">
						<text class="cuIcon-warnfill margin-right"></text>
						<text >{{item.title}}</text>
					</view>
					<view class="margin text-grey text-df">
						{{item.summary}}
					</view>
					<view class="margin text-sm text-gray text-right">
						{{formatDateTime(item.createdDate)}}
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import * as commonUserNoticeApi from '@/api/common/commonUserNoticeApi.js'
	import * as storage from '@/util/storage.js'
	import {
		formatDateTime
	} from '@/util/formatTime.js'
	export default {
		name: 'userName',
		data() {
			return {
				notices: [],
				userId: storage.getUserId(),
				language: storage.getLanguage(),
			}
		},
		computed: {
			themeConfig() {
				return this.$store.state.themeConfig
			}
		},
		onLoad(option) {
			if (option.noticeId) {
				this.noticeId = option.noticeId
			}
		},
		onShow() {
			this.pageGetUserNotice()
		},
		methods: {
			formatDateTime(time) {
				return formatDateTime(time, this.$t('unKnow'))
			},
			gotoInfo(item) {
				uni.navigateTo({
					url: `/pages/userNoticeContent/userNoticeContent?noticeId=${item.noticeId}`
				})
			},
			pageGetUserNotice() {
				commonUserNoticeApi.pageGetUserNotice({
					userId: this.userId,
					noticeId: this.noticeId,
					pageSize: 10,
					currentPage: 1,
					language: this.language
				}).then((res) => {
					if (res.data) {
						this.notices = res.data.data;
					}
				})
			}
		},
		onShareAppMessage(res) {
			let nickName = storage.getNickName()
			let shortCompanyName = storage.getShortCompanyName()
			return {
				title: `${nickName}${this.$t('share')}${shortCompanyName}`,
				path: `/pages/userNotice/userNotice`,
				success: (res) => {
					// console.log(res)
				}
			}
		}
	}
</script>

<style>
	page {
		background-color: #f8f8f8;
	}
</style>
